package com.tilaiedu.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Author xlzhang
 * Date 2022/5/23 10:26
 * Version 1.0
 * Description TODO
 */
@Controller
// 代表当前类的所有资源路径都需要加上这个目录
//@RequestMapping("/user")
public class HelloController {
    // get post put delete option
    // 默认支持所有请求
    // HTTP Status 405 – 方法不允许 请求方式不正确
    @RequestMapping(value = "/user/hello",
            method = {RequestMethod.GET,RequestMethod.POST},
            headers ="cookie")
    public ModelAndView hello(String name){
        System.out.println("HelloController.hello");
        ModelAndView modelAndView = new ModelAndView();
        // 这个相当于之前的request.setAtrabute(), 将数据添加到请求域中
        modelAndView.addObject("info","name="+name+" age=");
        modelAndView.setViewName("success");
        return modelAndView;
    }

    //@RequestMapping(value = "/user",method = RequestMethod.GET)
    @GetMapping("/user")
    public String hello2(){
        System.out.println("HelloController.hello2");
        return "success";
    }

    @RequestMapping("/a*/**/testAnt")
    public String testAnt(){
        return "success";
    }

    @RequestMapping("/index.html")
    public String openIndex(HttpServletRequest request){
        request.getSession();
        return "index";
    }

    @RequestMapping("/success.html")
    public String openSuccess(){
        return "success";
    }
}
